package com.zxkj.commonpatrol.utils;

import android.content.Context;
import android.view.View;
import android.widget.EditText;

import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.tools.TimeUtil;
import com.xuexiang.xui.widget.dialog.MiniLoadingDialog;
import com.xuexiang.xui.widget.picker.widget.OptionsPickerView;
import com.xuexiang.xui.widget.picker.widget.TimePickerView;
import com.xuexiang.xui.widget.picker.widget.builder.OptionsPickerBuilder;
import com.xuexiang.xui.widget.picker.widget.builder.TimePickerBuilder;
import com.xuexiang.xui.widget.picker.widget.listener.OnOptionsSelectListener;
import com.xuexiang.xui.widget.picker.widget.listener.OnTimeSelectChangeListener;
import com.xuexiang.xui.widget.picker.widget.listener.OnTimeSelectListener;


import java.util.Date;

public class AddViewTypeUtils {

    public MyBaseDataCallBack mDataCallBack;

    //数据回调接口
    public interface MyBaseDataCallBack<T> {
        void onDataSuccessCallBack( T t);
        void onDataFailCallBack(T t,T t1);
    }




    public  static  void AddDatatime(EditText editText, Context context,MyBaseDataCallBack mDataCallBack){
        TimePickerView mTimePicker = new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelected(Date date, View v) {

                editText.setText(TimeUtil.getDateByDates(date));
                mDataCallBack.onDataSuccessCallBack(TimeUtil.getDateByDates(date));

            }
        })
             .setTimeSelectChangeListener(new OnTimeSelectChangeListener() {
                    @Override
                    public void onTimeSelectChanged(Date date) {
                        //不能早於當天
//                        Date nowDate = new Date();
//                        boolean before = date.before(nowDate);
//                        if (before) {
//                            //早于今天
//                            XToast.error(QuickAddActivity.this, getString(R.string.before_time)).show();
//                        }
                    }
                })


                .setType(new boolean[]{true, true, true, false, false, false})
                .isCenterLabel(false)
                .setSubCalSize(16)
                .setSubCalSize(16)
                .setCancelText("取消")//取消按钮文字
                .setSubmitText("確認")//确认按钮文字
                .setLabel("", "", "", "", "", "")
                .setTitleText("請選擇時間")
                .build();


        mTimePicker.show();

    }

    public  static  void AddSpinner(EditText editText, Context context,String[] o,MyBaseDataCallBack mDataCallBack){

        OptionsPickerView<Object> mDeciveType = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
            @Override
            public boolean onOptionsSelect(View view, int options1, int options2, int options3) {
                editText.setText(o[options1]);
                mDataCallBack.onDataSuccessCallBack(o[options1]);
                return false;
            }


        }).setCancelText("取消")//取消按钮文字
                .setSubmitText("確認")//确认按钮文字
                .setTitleText("請選擇")
                .setSubCalSize(16)
                .setSubCalSize(16)
                .build();
        mDeciveType.setPicker(o);
        mDeciveType.show();
    }

}
